package com.example.cici.cclight.fragment;

import android.bluetooth.BluetoothSocket;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import com.example.cici.cclight.R;
import com.example.cici.cclight.util.SocketUtil;

import java.io.OutputStream;

public class CircleFragment extends Fragment {
    private Button button;
    private BluetoothSocket socket;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_tab_circle,null);
        button = (Button) view.findViewById(R.id.circle);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sendColor();
            }
        });
        return view;
    }

    private void sendColor() {
        OutputStream os = null;
        try {
            socket = SocketUtil.getInstance().getBluetoothSocket();
            os = socket.getOutputStream();
            os.write("+M,2:2;".getBytes());
            os.flush();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
